/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.research_award.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.research_award.entity.TbResearchAward;
import com.thinkgem.jeesite.modules.research_award.service.TbResearchAwardService;

/**
 * 科研获奖Controller
 * @author hang
 * @version 2017-01-15
 */
@Controller
@RequestMapping(value = "${adminPath}/research_award/tbResearchAward")
public class TbResearchAwardController extends BaseController {

	@Autowired
	private TbResearchAwardService tbResearchAwardService;
	
	@ModelAttribute
	public TbResearchAward get(@RequestParam(required=false) String id) {
		TbResearchAward entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbResearchAwardService.get(id);
		}
		if (entity == null){
			entity = new TbResearchAward();
		}
		return entity;
	}
	
	@RequiresPermissions("research_award:tbResearchAward:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbResearchAward tbResearchAward, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbResearchAward> page = tbResearchAwardService.findPage(new Page<TbResearchAward>(request, response), tbResearchAward); 
		model.addAttribute("page", page);
		return "modules/research_award/tbResearchAwardList";
	}

	@RequiresPermissions("research_award:tbResearchAward:view")
	@RequestMapping(value = "form")
	public String form(TbResearchAward tbResearchAward, Model model) {
		model.addAttribute("tbResearchAward", tbResearchAward);
		return "modules/research_award/tbResearchAwardForm";
	}

	@RequiresPermissions("research_award:tbResearchAward:edit")
	@RequestMapping(value = "save")
	public String save(TbResearchAward tbResearchAward, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbResearchAward)){
			return form(tbResearchAward, model);
		}
		tbResearchAwardService.save(tbResearchAward);
		addMessage(redirectAttributes, "保存科研获奖成功");
		return "redirect:"+Global.getAdminPath()+"/research_award/tbResearchAward/?repage";
	}
	
	@RequiresPermissions("research_award:tbResearchAward:edit")
	@RequestMapping(value = "delete")
	public String delete(TbResearchAward tbResearchAward, RedirectAttributes redirectAttributes) {
		tbResearchAwardService.delete(tbResearchAward);
		addMessage(redirectAttributes, "删除科研获奖成功");
		return "redirect:"+Global.getAdminPath()+"/research_award/tbResearchAward/?repage";
	}

}